
 #ifndef SCENE_H
 #define SCENE_H

 #include <QGraphicsScene>
#include <QPixmap>
#include "diagramitem.h"
#include "edge.h"
#include <time.h>
#include <sbml/SBMLTypes.h>



 
QT_BEGIN_NAMESPACE
class QGraphicsSceneMouseEvent;
class QMenu;
class QPointF;
class QGraphicsLineItem;
class QFont;
class QGraphicsTextItem;
class QColor;
QT_END_NAMESPACE


 class Scene : public QGraphicsScene
 {
     Q_OBJECT

 public:
 
	enum Mode { Insert, Move, InsertEdge, InsertConEdge, Text };
	
    Scene( QObject *parent = 0);
    QFont font() const
         { return myFont; }
    QColor textColor() const
         { return myTextColor; }
    QColor itemColor() const
         { return myItemColor; }
    QColor lineColor() const
         { return myLineColor; }
	 
	 Mode myMode;
         QVector<QPointF> points;
         QList<Edge*> edges;
         QList<DiagramItem*> diagramItems;
		 QList<QString> ids;
	 bool grid;
	 void updatePoints(bool t);
	 DiagramItem* returnItem(QString id);
	 Edge* returnPath(QString id);
	 void filtering();
	 void unfiltering();
	 QString saveToXML();
	 void loadFromXml(QIODevice *xmlData);
	 void loadFromXmlInteraction(QIODevice *xmlData);
	 void drawSemiAuto(QList<QGraphicsItem *> items);
         bool validateSBML (SBMLDocument* sbmlDoc);
         bool writeExampleSBML(const SBMLDocument* sbmlDoc, const QString& filename);
		 //QString Scene::writeExampleSBML(const SBMLDocument* sbmlDoc);
         SBMLDocument* createExampleEnzymaticReaction(const QString &modelName);
         void saveToSBML(const QString &fileName);
		 char* writeExampleSBML2(const SBMLDocument* sbmlDoc);
		 char* saveToSBML2();
	 int cross(const QPointF &p,const QPointF &p2);
	 void insertHeap(const QPointF &p);
	 void decreaseKeyHeap(const QPointF &p);
	 void deleteMinHeap();
	 void insertHeap2(const QPointF &p);
	 void decreaseKeyHeap2(const QPointF &p);
	 void deleteMinHeap2();
	 bool generateToAutoLayout();
	 void addBranch(bool right);
	 
 
	 

public slots:
	void setMode(Mode mode);
	void setItemType(DiagramItem::DiagramType type);
	void setArrowType(Edge::EdgeType type);
	void diagramItemChange(DiagramItem *item);

 signals:
	void itemInserted(DiagramItem *item);
	void EdgeInserted(Edge *item);
	void itemSelected(QGraphicsItem *item);

 protected:
     void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
     void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
     void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
	 void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent);
	 void drawBackground ( QPainter * painter, const QRectF & rect ) ;	

 private:

	QGraphicsLineItem *line;
    DiagramItem::DiagramType myItemType;
    Edge::EdgeType myArrowType;
    QMenu *myItemMenu;
	QMap<QString, int> Letter;
    QGraphicsTextItem *addNumber;
    QFont myFont;
    QColor myTextColor;
    QColor myItemColor;
    QColor myLineColor;	
	QHash<QString, int> costArray;
	QHash<QString, QPointF> prevArray;
	QVector<QPointF> heap;
	QHash<QString, int> costArray2;
	QHash<QString, QPointF> prevArray2;
	QVector<QPointF> heap2;
    SBMLDocument* sbmlDoc ;
	double time;
	QGraphicsPathItem* paItem;

	
	
 };

 #endif
